class Solution {
public:
    bool wordPattern(string pattern, string s) {
        int cnt = 0;
        for (auto x : s) {
            if (x == ' ')cnt++;
        }
        if (cnt + 1 != pattern.size())return 0;
        unordered_map<char, string>mp;
        unordered_map<string, char>mp1;
        int idx = 0;
        for (auto x : pattern) {
            string temp;
            while (idx < s.size() && s[idx] != ' ') {
                temp += s[idx++];
            }
            idx++;
            cout << temp << endl;
            if (!mp.count(x) && !mp1.count(temp)) mp[x] = temp, mp1[temp] = x;
            else {
                if (mp[x] != temp || mp1[temp] != x)return 0;
            }
        }
        return 1;
    }
};